import java.math.BigInteger;
import java.util.Scanner;

public class demo05 {
    //二进制问题
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        long n=sc.nextLong();
        int k=sc.nextInt();
        int sum=0;
        for (long i = 1; i < n; i++) {
            int count=0;
            String s=i+"";
            String num=new BigInteger(s,10).toString(2);
            for (int j = 0; j < num.length(); j++) {
                if(num.charAt(j)=='1'){
                    count++;
                }
            }
            if(count==k){
                sum++;
            }
        }
        System.out.println(sum);
    }
}
